package com.crane.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


@Configuration
@EnableSwagger2

public class AppSwagger2 {

    @Bean
    public Docket createAppApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("App接口").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.crane.app.web.controller"))
                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("接口管理").description("接口描述")
                .contact(new Contact("bealon", "ccsu123456@qq.com", "ccsu123456@qq.com")).version("1.0").build();
    }

    private List<Parameter> bulidParameter() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder debugPar = new ParameterBuilder();
        debugPar.name("Authorization").hidden(true).description("token选项").modelRef(new ModelRef("string")).parameterType("header").defaultValue("").build();
        pars.add(debugPar.build());
        return pars;
    }

}
